package com.jy.api.controller.team;

import com.jy.api.domain.AddStoreTeamsReq;
import com.jy.api.service.StoreService;
import com.jy.api.service.TeamService;
import com.jy.api.service.TeamTransactionService;
//import com.jy.api.service.impl.MailService;
import com.jy.api.signUpReq.team.AddTeamReq;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * Created by xiaohua on 2018/12/24.
 */
@Slf4j
@RestController
@RequestMapping(value = "v1/team", produces = "application/json;charset=utf-8")
public class TeamController {


    @Autowired
    private TeamService teamService;
    @Autowired
    private TeamTransactionService teamTransactionService;
    @Autowired
    private StoreService storeService;
    /*@Autowired
    private MailService mailService;*/

    @PostMapping("add-team")
    public ResponseEntity addNewTeam(@RequestBody AddTeamReq req) {
        return ResponseEntity.ok(teamService.addNewTeam(req));
    }

    @PostMapping("update-team")
    public ResponseEntity updateTeam(@RequestBody AddTeamReq req) {
        return ResponseEntity.ok(teamService.updateTeam(req));
    }

    @GetMapping("find-all")
    public ResponseEntity findAllTeam() {
        return ResponseEntity.ok(teamService.findAllTeam());
    }

    @PostMapping("add-store")
    public ResponseEntity addStoreTeams(@RequestBody AddStoreTeamsReq req) {
        return ResponseEntity.ok(teamTransactionService.addStoreTeams(req));
    }

    @GetMapping("find-teams")
    public ResponseEntity findByTeamId(@RequestParam("id") int id) {
        return ResponseEntity.ok(teamTransactionService.findByTeamsId(id));
    }


    @PostMapping("delete-team")
    public ResponseEntity deleteTeam(@RequestParam("id") int id) {
        return ResponseEntity.ok(teamTransactionService.deleteByTeamTranId(id));
    }


    @GetMapping("find-store")
    public ResponseEntity findStore(@RequestParam("name") String name) {
        return ResponseEntity.ok(storeService.findByStoreNameLike(name));
    }


    /*@GetMapping("mail")
    public ResponseEntity testMail() {
        try {
            System.out.println("start send simple mail");
            mailService.sendSimpleMail("707163941@qq.com", "测试邮件发送", "测试邮件发送");
            System.out.println("end send simple mail");
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("error");
        }
        return ResponseEntity.ok("测试成功");

    }*/

}
